package com.dsteiner.widgets.client;



public class StringUtil {

	public static String toLowerCase(String string) {
		return string.toLowerCase();
//		if(string == null || string.length() == 0)
//			return string;
//		String[] split = string.split(" ");
//		StringBuffer result = new StringBuffer();
//		for (int i = 0; i < split.length; i++) {
//			result.append(split[i].substring(0,1).toLowerCase()).append(split[i].substring(1));
//			if(i + 1 < split.length)
//				result.append(" ");
//		}
//		return result.toString();
	}

	public static String toUpperCaseFirstChar(String text) {
		if(text == null)
			return null;
		String[] split = text.split(" ");
		StringBuffer result = new StringBuffer();
		for (int i = 0; i < split.length; i++) {
			result.append(split[i].substring(0,1).toUpperCase()).append(split[i].substring(1));
			if(i + 1 < split.length)
				result.append(" ");
		}
		return result.toString();
	}
	
	public static String toLowerCaseFirstChar(String text) {
		if(text == null)
			return null;
		String[] split = text.split(" ");
		StringBuffer result = new StringBuffer();
		for (int i = 0; i < split.length; i++) {
			result.append(split[i].substring(0,1).toLowerCase()).append(split[i].substring(1));
			if(i + 1 < split.length)
				result.append(" ");
		}
		return result.toString();
	}

	public static boolean isEmpty(String string) {
		return string == null || string.equals("") || string.equals("null");
	}

	public static String toHtml(String string) {
		if(string == null)
			return null;
		string = string.replaceAll("\n", "<br>");
		string = string.replaceAll("([\\w\\.\\-\\_]+@([\\w\\.\\-\\_]+))","<a href=\"mailto:$1\">$1</a>");
//		string = string.replaceAll("www([\\w\\.\\-\\_]+)","<a href=\"http:\\/\\/$0\" target=\"_blank\">$0</a>");
		string = string.replaceAll("(http:\\/\\/)?(www([\\w\\.\\-\\_]+))","<a href=\"http:\\/\\/$2\" target=\"_blank\">$2</a>");
		return string;
	}
	public static String toText(String string) {
		return string != null ? string.replaceAll("<br/>", "\n").
				replaceAll("<br>", "\n").replaceAll("</P>", "\n").replaceAll("<P>", "") : null;
	}
}
